const compress = (chars) => {
  let k = chars[0];
  let i = 0;
  let j = 0;
  let len = chars.length;
  while (len) {
    if (k !== chars[0]) {
      chars.push(k);
      if (j > 1) chars.push(...(j + ""));
      j = 0;
      k = chars[0];
    }
    chars.shift();
    j++;
    len--;
  }
  chars.push(k);
  if (j > 1) chars.push(...(j + ""));
  return chars.length;
};
